{extend name="public:layout" /}
{block name="title"}添加抢购{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 抢购列表</a></li>
                <li class="active">添加抢购</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">

                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">抢购名称</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入抢购名称" name="groupbuy_name" value="" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">开始时间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control laydatetime" name="begin_time" value="" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">结束时间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control laydatetime" name="end_time" value="" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">抢购商品</label>
                    <div class="col-sm-10">
                        <a class="btn btn-info" onclick="showOneGoods(this,setOneGoods);"
                           data-field="sku_id"
                           data-siteid="{$site_id}"
                           data-url="{:url('plus/Goods/selectone')}"
                        >选择抢购商品</a>
                        <div id="goodsinfo"></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">抢购价格</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="groupbuy_price" value="" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">限购数量</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="groupbuy_limit" value="1" datatype="*" />
                        <p class="help-block">每个买家ID可抢购的最大数量，不限数量请填 "0"</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">抢购活动图片</label>
                    <div class="col-sm-4">
                        <p class="form-control-static">
                            {:widget('common/Form/singleImg',['goodsbuy_thumb','',$uid])}
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">虚拟购买数量</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="virtual_count" value="0" datatype="*" />
                        <p class="help-block">虚拟购买数量，只用于前台显示，不影响成交记录</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">抢购活动介绍</label>
                    <div class="col-sm-10">
                        <p class="form-control-static">
                            {:widget('common/Form/ueditor',['groupbuy_content','',$uid])}
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" type="button" id="btnSub">保存内容</button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script id="set-goodsinfo-tpl" type="text/html">
    <table class="table table-bordered">
        <thead>
        <tr>
            <th width="50">#</th>
            <th width="300">商品名称</th>
            <th width="100">销售价</th>
            <th width="100">库存</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>{{ sku_info.sku_id }}</td>
            <td>
                <img src="{{ sku_info.goods_thumb }}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                {{ sku_info.fulltitle }}
            </td>
            <td>{{ sku_info.simple_price }}元</td>
            <td>{{ sku_info.goods_stock }}</td>
        </tr>
        </tbody>
    </table>
    <input type="hidden" name="site_id" value="{{ sku_info.site_id }}" />
    <input type="hidden" name="site_name" value="{{ sku_info.site_name }}" />
    <input type="hidden" name="goods_id" value="{{ sku_info.goods_id }}" />
    <input type="hidden" name="sku_id" value="{{ sku_info.sku_id }}" />
    <input type="hidden" name="goods_name" value="{{ sku_info.goods_name }}" />
    <input type="hidden" name="sku_name" value="{{ sku_info.sku_name }}" />
    <input type="hidden" name="market_price" value="{{ sku_info.market_price }}" />
    <input type="hidden" name="simple_price" value="{{ sku_info.simple_price }}" />
</script>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        In('selectgoods');
        formatDate();
        ajaxSubForm('#btnSub');
    })
    function setOneGoods(field,sku){
        if(sku.sku_id>0){
            $("input[name='groupbuy_price']").val(sku.sku_info.simple_price);
            In('templete',function () {
                var html = template('set-goodsinfo-tpl', sku);
                $('#goodsinfo').html(html);
            })
        }
    }
    function delGoods(obj) {
        $(obj).closest('tr').remove();
    }
</script>
{/block}